$(function () {
    inChageallFun();
    $("body").on("click","#share_teacher",function () {
        popupTopicshare();
    });
    var isQuestion = $("#isQuestion").val();
    var teacherId = $("#teacherId").val();

    if(isQuestion == 1){
        findTeacherQuestionList();
    }else {
        teacherCourseList(1);
    }
    //图片数据懒加载
    lazyCourseImage();
    lazyStudentImage();
    //讲师简介模拟滚动条
    $('.teach-info-attr__cont p').slimScroll({
        height: '100%',
        railOpacity: 0.9,
        alwaysVisible: true
    });

    /**
     * 主页与全部课程切换效果
     */
    function inChageallFun() {
        var _inteach = $('.teach-info-index'),
            _allCour = $('.teach-info-allCourse__wrap');
        $('body').on('click', '#teachAllCourseBtn', function() {
            teacherCourseList(1);
            teachOrQuestion(_inteach,_allCour);
        })
        $('body').on('click', '#closeAllCourseBtn', function() {
            teachOrQuestion(_inteach,_allCour);
        })
    }
    function  teachOrQuestion(_inteach,_allCour){
      var that =  $("#teachAllCourseBtn");
        if(!_allCour.hasClass('tcShow')) {
            _inteach.addClass('tcShow');
            _allCour.addClass('tcShow');
            that.text(" TA的问答 ");
        }else{
            _inteach.removeClass('tcShow');
            _allCour.removeClass('tcShow');
            that.text(" 全部课程 ")
        }
        that.append("<i class=\"fa fa-angle-right\"></i>");
    }


    /**
     * 查询讲师的问题列表
     */
    function findTeacherQuestionList() {
        $.ajax({
            url: baseloaction + '/web/teacher/findTeacherQuestionList',
            data: {"teacherId": teacherId},
            type: 'post',
            dataType: 'text',
            beforeSend:function (XHR) {
                var loadText = '<div class="text-center pt10 pb10"><span class="loading"></span></div>';
                $("#teacher-question").html(loadText);
                return true;
            },
            success: function (result) {
                $("#teacher-question").html(result);
                lazyStudentImage();
            },
            error: function (error) {
                var _text = '<section class="no-data__wrap"><span class="no-data-ico"></span><p class="mt20"><span class="c-666">这个讲师有点懒，还没有回答问题~~~</span></p></section>'
                $("#teacher-question").html(_text);
            }
        })
    }

    /**
     * 查询讲师的课程列表
     * @param pageNo
     */
    function teacherCourseList(pageNo) {
        var params = {"teacherIds": teacherId};
        params = JSON.stringify(params)
        getPageAjaxData({
            url: baseloaction + '/web/teacher/findTeacherCourseList',
            contextId: 'course-list-context',
            pageNo: pageNo,
            pageCall: teacherCourseList,
            params: params,//查询参数
            callback: function (pageNo) {
                $("#teacher-course-sum").text(total);
                lazyCourseImage();
            }
        })
    }
})